#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc2_r12_aux_ne.info <<'%EOF%'
   cc2_r12_aux_ne
   ------------
   Molecule:         Ne in D2h
   Wave Function:    CC2-R12/B/1  6-31G/6-311++G(3df,3pd)
   Test Purpose:     test CC2-R12/CCSD(R12) using .R12ORB option
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc2_r12_aux_ne.mol <<'%EOF%'
BASIS
6-31G 6-311++G(3df,3pd)
Ne

    2  0 3  X  Y  Z  0.10D-14
 1     10.    1
Ne       0.0000000000000     0.0000000000000     0.0000000000000       *
 2     10.    1
Ne       0.0000000000000     0.0000000000000     0.0000000000000       *
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc2_r12_aux_ne.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTION
.DIRECT
*MOLBAS
.R12AUX
**INTEGRALS
.R12
**WAVE FUNCTION
.CC
*ORBITAL
.MOSTART
 H1DIAG
.AO DEL
 1.0D-7
.R12ORB
 0 1 0 0 0 0 0 0
*SCF INPUT
.THRESH
 1.0D-10
*CC INPUT
.CC2
.CCSD
.PRINT
 3 
.THRENR
 1.0D-14
.MAX IT
 100
.FREEZE
 1 0
*R12 INPUT
.NO HYB
.CC2
 1B
**END OF DALTON INPUT
%EOF%
#######################################################################


#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc2_r12_aux_ne.check
cat >>cc2_r12_aux_ne.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

#                                                                                
#            Total SCF   energy:                  -128.4738768705                
#            Total MP2-R12/B energy:              -128.7274586700                
#            Total CC2-R12/B energy:              -128.7277137493                
#
#
#            Total SCF   energy:                  -128.4738768705                
#            Total RSTAR(R12)/B energy:           -128.7277137493                
#            Total CCSD(R12)/B energy:            -128.7225057304                
#  
CRIT1=`$GREP "Total MP2-R12/B energy: *\-128\.7274586700" $log | wc -l`
TEST[1]=`expr $CRIT1` 
CTRL[1]=2
ERROR[1]="MP2-R12/B ENERGY NOT CORRECT"

CRIT2=`$GREP "Total CC2-R12/B energy: *\-128\.7277137493" $log | wc -l`
TEST[2]=`expr $CRIT2`
CTRL[2]=2
ERROR[2]="CC2-R12/B ENERGY NOT CORRECT"

CRIT3=`$GREP "Total CCSD\(R12\)/B energy: *\-128\.7225057304" $log | wc -l`
TEST[3]=`expr $CRIT3`
CTRL[3]=2
ERROR[3]="CCSD(R12)/B ENERGY NOT CORRECT"


PASSED=1
for i in 1 2 3 
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi                
%EOF%
#######################################################################
